<template>
  <div>
    <div class="My_title__39w3V" v-if="isshow" >
      <img class="My_bg__2j-VX" src="http://liufusong.top:8080/img/profile/bg.png" alt="背景图" />
      <div class="My_info__eOYeg">
        <div class="My_myIcon__3cKIV">
          <img
            class="My_avatar__2Fbh7"
            src="http://liufusong.top:8080/img/profile/avatar.png"
            alt="icon"
          />
        </div>
        <div class="My_user__B6O1D">
          <div class="My_name__3U2NB">游客</div>
          <div class="My_edit__3wqlv">
            <a
              role="button"
              class="am-button am-button-primary am-button-small am-button-inline"
              aria-disabled="false"
            >
              <span @click="$router.push('/login')">去登录</span>
            </a>
          </div>
        </div>
      </div>
    </div>
    <div class="My_title__39w3V" v-else>
      <img class="My_bg__2j-VX" src="http://liufusong.top:8080/img/avatar.png" alt="背景图" />
      <div class="My_info__eOYeg">
        <div class="My_myIcon__3cKIV">
          <img
            class="My_avatar__2Fbh7"
            src="http://liufusong.top:8080/img/profile/avatar.png"
            alt="icon"
          />
        </div>
        <div class="My_user__B6O1D">
          <div class="My_name__3U2NB">好客_508871</div>
          <div class="My_auth__1KSIg">
            <span class="span" @click="delFn()">退出</span>
          </div>
          <div class="My_edit__3wqlv">
            编辑个人资料>
            <span class="My_arrow__1LOxs">
              <i class="iconfont icon-arrow"></i>
            </span>
          </div>
        </div>
      </div>
    </div>
    <van-grid :column-num="3" :gutter="10" :border="false" route>
      <van-grid-item icon="star-o" text="我的收藏" to="/favorate"/>
      <van-grid-item icon="wap-home-o" text="我的出租" to="/rent"/>
      <van-grid-item icon="eye-o" text="看房记录" />
      <van-grid-item icon="debit-pay" text="成为房主" />
      <van-grid-item icon="manager-o" text="个人资料" />
      <van-grid-item icon="chat-o" text="联系我们" />
    </van-grid>
    <div class="My_ad__1wZZj">
      <img src="http://liufusong.top:8080/img/profile/join.png" alt />
    </div>
  </div>
</template>

<script>
import requset from '@/utils/requset'
export default {
  name: 'VueHaowuProfile',
  data () {
    return {
      token: '',
      isshow: true
    }
  },
  created () {
    this.token = localStorage.getItem('user')
    if (this.token !== null) {
      this.isshow = !this.isshow
    }
  },
  methods: {
    delFn () {
      this.$dialog.confirm({
        title: '提示',
        message: '确定退出吗?',
        confirmButtonColor: 'blue'
      })
        .then(async () => {
          const res = await requset({
            url: '/user/logout',
            method: 'post'
          })
          console.log(res)
          this.$toast.success(res.description)
          localStorage.removeItem('user')
          this.$router.push('/login')
        })
        .catch((err) => {
          console.log(err)
        })
    }
  }
}
</script>

<style lang="less" scoped>
.My_title__39w3V {
  min-height: 300px;
  position: relative;
  .My_bg__2j-VX {
    width: 100%;
  }
  .My_info__eOYeg {
    position: absolute;
    background: #fff;
    width: 75%;
    height: 55%;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    box-shadow: 0 0 10px 3px #ddd;
    margin: 50px auto 0;
    padding: 0 20px;
    text-align: center;
    font-size: 13px;
    .My_myIcon__3cKIV {
      position: relative;
      transform: translateY(-50%);
      border-radius: 50%;
      width: 70px;
      height: 70px;
      border: 5px solid #f5f5f5;
      display: inline-block;
      box-shadow: 0 2px 2px #bdbdbd;
      .My_avatar__2Fbh7 {
        width: 100%;
        border-radius: 50%;
      }
    }
    .My_user__B6O1D {
      padding-top: 15px;
      .My_name__3U2NB {
        margin-top: -30px;
        margin-bottom: 10px;
      }
      .My_edit__3wqlv {
        color: #999;
        font-size: 12px;
        margin-top: 20px;
        a {
          display: flex;
          text-align: center;
          span {
            margin-left: 110px;
            border-radius: 3px;
            width: 60px;
            text-align: center;
            height: 30px;
            line-height: 30px;
            font-size: 13px;
            background-color: #21b97a;
            color: #fff;
          }
        }
      }
    }
  }
}
/deep/ .van-grid-item__text {
  font-size: 14px !important;
}
.My_ad__1wZZj {
  text-align: center;
  margin-top: 10px;
  img {
    width: 90%;
  }
}
.span {
          border-radius: 30px;
    color: #fff;
    padding: 2px 15px;
    background: #21b97a;
    font-size: 12px;

}
</style>
